﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using S.Common.EditReproductivePresenceStateHelper;
using S.Common.EditWanderStateHelper;
using S.PurchaseAndSales.Api.Application.Command.SheepSaleCommand;
using S.PurchaseAndSales.Domain.Model;
using S.PurchaseAndSales.Infrastructure.Interface.SalesForm;

namespace S.PurchaseAndSales.Api.Application.CommandHandlers.SheepSaleHandler
{
    public class SheepSaleBUpdateMoneyStateCommandHandler : IRequestHandler<SheepSaleBUpdateMoneyStateCommand, bool>
    {
        private readonly ISheepSaleRepository sheepSaleRepository;
        private readonly IMapper mapper;
        private readonly IConfiguration configuration;
        private readonly IHttpContextAccessor httpContextAccessor;

        public SheepSaleBUpdateMoneyStateCommandHandler(ISheepSaleRepository sheepSaleRepository, IMapper mapper, IConfiguration configuration, IHttpContextAccessor httpContextAccessor)
        {
            this.sheepSaleRepository = sheepSaleRepository;
            this.mapper = mapper;
            this.configuration = configuration;
            this.httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// 批量修改财务状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(SheepSaleBUpdateMoneyStateCommand request, CancellationToken cancellationToken)
        {
            foreach(var item in request.sheepSaleModels)
            {
                item.MoneyCheckState = 2;
            }
            return await sheepSaleRepository.BatchUpdateMoneyState(request.sheepSaleModels);
        }
    }
}
